<?php
require('set.php');
$userid = $_GET['userid'];
require('../cofd/functions.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>User-Center</title>
<link href="/ast/layui/css/layui.css" rel="stylesheet">
<script src="/ast/layui/layui.js"></script>
</head>
<body>
<style>
.greenzt{
  color:green;
}
.redzt{
  color:red;
}
.img_book{
  width:100px;
  height:150px;
  border-radius:10px;
  object-fit: cover;
  border:1px solid #ccc;
  padding:2px;
  margin:5px;
}
.booklist{
  overflow-y: scroll;
}
</style>
<section class="rt_wrap content mCustomScrollbar">
 <div style="display: none;" id='centercont' class="rt_content">
  <div class="booklist">
 <div class="admin_tab_cont" style="display:block;">
       <div class="cont_col_lt mCustomScrollbar" style="height:500px;width:100%">
           <table class="table fl">
            <tr>
             <th>书名</th>
             <th>介绍</th>
             <th>书图</th>
             <th>状态</th>
             <th>操作</th>
            </tr>
            <tr>
            <?php 
            require('../cofd/common.php');
            $sql = "SELECT * FROM novel WHERE fromer = $userid";
            $result = mysqli_query($conn, $sql);
            while($row = mysqli_fetch_assoc($result)){
             echo '<td class="center">'; echo $row['name'];echo '</td>';
             echo '<td class="center">';echo $row['content'];echo '</td>';
             echo '<td class="center"><img class="img_book" src="';echo $row['img'];echo '"</img></td>';
             echo '<td class="center">';if($row['refuse'] == 1){
              echo '<span class="greenzt">审核通过</span>';
             }else{
              echo '<span class="redzt">审核中</span>';
             };echo '</td>';
             echo '<td class="center">
             <a onclick="gowrite(`'.urlencode(encrypt($row['zj'],'E','xhpayencrypt')).'`)" class="inner_btn">更新</a>
             <a onclick="delthebook(`'.$row['name'].'`)" class="inner_btn">删除</a>
             </td>';
           echo'
            </tr>
            <tr>';
            }
             ?>
            </tr>
           </table>
       </div>
</div>
          </div>
          <a class="link_btn" id="newbook">New Book</a>
        </div>
</section>
</body>
</html>
<script>
  var userid = sessionStorage.getItem('user');
  fetch('/cofd/writer.php?userid='+userid)
  .then(response => response.json())
  .then(data => {
    if(data.code === 200){
      document.querySelector('.rt_content').style.display = 'block';
    }else{
      Qmsg.error(data.msg);
      document.querySelector('.rt_content').remove();
    }
  })
  </script>
  <script>
	(function($){
		$(window).load(function(){
			$("a[rel='load-content']").click(function(e){
				e.preventDefault();
				var url=$(this).attr("href");
				$.get(url,function(data){
					$(".content .mCSB_container").append(data); 
					$(".content").mCustomScrollbar("scrollTo","h2:last");
				});
			});		
			$(".content").delegate("a[href='top']","click",function(e){
				e.preventDefault();
				$(".content").mCustomScrollbar("scrollTo",$(this).attr("href"));
			});	
		});
	})(jQuery);
</script>
<script>
 function delthebook(delthename){
  if(!confirm('确定要删除该书籍吗？删除后将无法恢复')){
    return false;
  }
  loading_load_show();
   fetch('/cofd/novel.php?cz=del&book='+delthename)
   .then(response => response.json())
   .then(data => {
    if(data.code === 200){
      Qmsg.success(data.msg);
    }else{
      Qmsg.error(data.msg);
    }
    })
    loading_load_hide();
    setTimeout(function(){
      location.reload();
    },1000);
 }
 function gowrite(bookname){
  var url = 'bookupdate.php?zj='+bookname;
  window.location.href=url;
 }
 function newbook(){
  layui.use(['element'], function(){
            var element = layui.element;
            layer.open({
                type: 2,
                title: '新book',
                shadeClose: true,
                shade: 0.8,
                area: ['900px', '60%'],
                shadeClose: false,
                content: 'newbook.php'
            });   
        });
 }
 document.getElementById('newbook').addEventListener('click',newbook);
</script>
